﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////


#pragma once
#include "GnufItem.h"

namespace gnuf {
    class Toolbar;
    class TreeBoard;
    class TreeNode;
    class FamilyTypeButton;
    class SearchBox;
    class QtFamilyTypes;
    class QtFamilyTypeButton;

    typedef TreeNode Family;
    typedef TreeNode FamilyType;

    class GNUF_BASE_EXPORT FamilyTypes final : public ItemWith<QtFamilyTypes>
    {
        CANNOT_COPY_OR_ASSIGN(FamilyTypes)
    public:
        static const EItemType Type;
        explicit FamilyTypes(Toolbar *);
        virtual ~FamilyTypes();

        typedef std::list< gcmp::OwnerPtr<FamilyType> > Contents;
        typedef std::vector< FamilyType * > RawContents;

        Family* addFamily();
        FamilyType* addFamilyType(Family*);

        void setCurrentFamilyType(FamilyType*,bool callBack = true);
        void setCurrentFamily(Family*, bool callBack = true);

        FamilyType* currentFamilyType();

        const FamilyTypes::Contents& contents() const;
        FamilyTypes::RawContents rawContents();

        void clearContents();
        
        inline TreeBoard* familyTree() { return m_familyTree.get(); }
        inline FamilyTypeButton* familyTypeButton() { return m_familyButton.get(); }
        inline FamilyTypeButton* addFamilyTypeButton() { return m_addFamilyButton.get(); }
        inline FamilyTypeButton* editFamilyTypeButton() { return m_editFamilyButton.get(); }
        inline SearchBox* searchBox() { return m_searchBox.get(); }
        
    protected:
        // Inherits from Item...
        virtual void onDisconnectFromMyQtItem() override;
        virtual void onPostAbilityChanged() override;
    private:
        gcmp::OwnerPtr<FamilyTypeButton> m_familyButton;
        gcmp::OwnerPtr<FamilyTypeButton> m_addFamilyButton;
        gcmp::OwnerPtr<FamilyTypeButton> m_editFamilyButton;
        gcmp::OwnerPtr<SearchBox> m_searchBox;
        gcmp::OwnerPtr<TreeBoard> m_familyTree;
    };

    class GNUF_BASE_EXPORT FamilyTypeButton final : public ItemWith<QtFamilyTypeButton>
    {
        CANNOT_COPY_OR_ASSIGN(FamilyTypeButton)
    public:
        static const EItemType Type;
        FamilyTypeButton(Item*);
        virtual ~FamilyTypeButton(){}

        void assignInfo(const Info&);
        
        // for the situation that icon and tooltips demonstration use different pixmap
        void assignHoveredInfo(const Info& info);
        const Info* hoveredInfo() const { return m_hoveredInfo.get(); }
    protected:
        // Inherits from Item...
        virtual void onDisconnectFromMyQtItem() override;
        virtual void onPostAbilityChanged() override;
        virtual void onPostInfoChanged() override;
        virtual void onPostVisibilityChanged() override;
        virtual void onPostAppearanceSettingChanged() override;

    private:
        gcmp::OwnerPtr<Info> m_info;
        gcmp::OwnerPtr<Info> m_hoveredInfo;
    };
}
